% equation of the characteristic polynomial is from :
% http://en.wikipedia.org/wiki/Characteristic_polynomial
%l^3-trace(A)*l^2+c2*l-det(A)=0 
%c2=(1/2)*((trace(A))^2 -trace(A*A))
% so in standard form: a3 is one and: 


%syms a b c d e f g h i real % elements of A where A = G*G'
clc 
clear all
width=1024;
height=768;
[ F, K,ps , badpoints,corrs, FFormatted, corrsFormatted,EFormatted,spacePts,widthm,heightm,FFormattedCLEAN,FCLEAN  ] = generateF( 0,0,1,40,0,5,0,0 ,width,height,0);
F=F{1,1};
K=K{1,1};
K(1,1)=200;
G=(K')*F*K;
A=10000*(G*G');



%A=[a b c ; d e f ; g h i];
a2=-trace(A);
a1=(1/2)*((trace(A))^2 -trace(A*A));
a0=-det(A);


% finding the roots
Q=((3*a1)-(a2^2))/9;
R=((9*a2*a1)-(27*a0)-(2*a2^3))/54;
D=Q^3+R^2;
S=(R+sqrt(D))^(1/3);
T=(R-sqrt(D))^(1/3);



z1=((-1/3)*a2)+(S+T)
z2=((-1/3)*a2)-((1/2)*(S+T))-((1/2)*(1i)*(sqrt(3))*(S-T))
z3=((-1/3)*a2)-((1/2)*(S+T))+((1/2)*(1i)*(sqrt(3))*(S-T))
DIS=((a1^2)*(a2^2))-(4*(a0*(a2^3)))-(4*(a1^3))+(18*a0*a1*a2)-(27*a0^2)


eig(A)


% clear all
% clc
% syms f1 f2 f3 f4 f5 f6 f7 f8 f9 foc1 foc2 xc yc real
% K=[foc1 0 xc ; 0 foc2 yc; 0 0 1]
% F=[f1 f2 f3 ; f4 f5 f6 ; f7 f8 f9 ]
% G=(K')*F*K
% A=G*G'
% a2=-trace(A);
% a1=(1/2)*((trace(A))^2 -trace(A*A));
% a0=-det(A);
% Q=((3*a1)-(a2^2))/9;
% R=((9*a2*a1)-(27*a0)-(2*a2^3))/54;
% D=Q^3+R^2;
% S=(R+sqrt(D))^(1/3);
% T=(R-sqrt(D))^(1/3);
% DIS=((a1^2)*(a2^2))-(4*(a0*(a2^3)))-(4*(a1^3))+(18*a0*a1*a2)-(27*a0^2)
% DISSIM=simplify(DIS)